import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    requireNativeComponent,
    findNodeHandle,
    UIManager
} from 'react-native';

const NativeJzAdView = requireNativeComponent('ReactJzAdView2', null);

// 鲸准广告
export default class JzAdView2 extends Component {

    // static defaultProps = {
    //     visible: false,
    //     style: null
    // };

    render() {        
        return (
            <NativeJzAdView style={this.props.style}
                ref={ref => this.nativeJzAdView = ref} />
        );
    }

    requestAd() {
        console.log('AAA-333-jz', 'requestAd()');
        
        this._dispatchCommand('requestAd');
        // this._dispatchCommand('requestAd', {'a': 1});

    }

    _dispatchCommand = (commandName, params = null) => {
        console.log('AAA-333-jz', '_dispatchCommand(): commandName = ' + commandName);
        console.log('AAA-333-jz', '_dispatchCommand(): commandId = ' + UIManager.ReactJzAdView.Commands[commandName]);
       

        UIManager.dispatchViewManagerCommand(
            this._findNodeHandle(), 
            UIManager.ReactJzAdView2.Commands[commandName], 
            // 1, // 对应 "requestAd"
            params);
    }

    _findNodeHandle = () => {
        const handle = findNodeHandle(this.nativeJzAdView);
        console.log('AAA-333-jz', 'findNodeHandle(): handle = ' + handle);
        return handle;
    }

}

const styles = StyleSheet.create({
    container: {
        width: 8,
        height: 8,
        borderRadius: 100,
        backgroundColor: '#B71C17'
    }
});
